package tcts0421;
// https://leetcode-cn.com/problems/contiguous-sequence-lcci/
public class 面试题1617连续数列0422 {
    public int maxSubArray(int[] nums) {
        int pre = 0;//之前和
        int max = nums[0];//最大值
        for(int i=0;i<nums.length;i++){
            pre = Math.max(nums[i],pre+nums[i]);
            max = Math.max(max,pre);

        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(new 面试题1617连续数列0422().maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4}));
    }
}
